package com.bridgeintelligent.tag.webserver.dim.mgmt.service.catalog;

import com.bridgeintelligent.tag.webserver.dim.mgmt.api.DimRep;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

/**
 * Created by JackCheung on 2019/9/9 10:12 PM.
 */
@Api(tags = "标签目录管理")
@RestController
@RequestMapping("api/dimCatalog")
public class CatalogController {


    private ICatalogService iCatalogService;

    public CatalogController(ICatalogService iCatalogService) {
        this.iCatalogService = iCatalogService;
    }

    @ApiOperation(value = "获取标签目录列表", notes = "标签目录管理")
    @GetMapping("list")
    public DimRep list() {
        return iCatalogService.findCatalogList();
    }


    @ApiOperation(value = "获取个人标签目录列表", notes = "标签目录管理")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "query", name = "indexId", value = "索引ID", required = true)})
    @GetMapping("showList")
    public DimRep showList(String indexId) {
        return iCatalogService.findShowCatalogList(false,indexId);
    }

    @ApiOperation(value = "获取标签目录列表", notes = "标签目录管理")
    @GetMapping("tree")
    public DimRep tree() {
        return iCatalogService.findDimTree(false);
    }

    @ApiOperation(value = "index-获取标签目录列表", notes = "标签目录管理")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "query", name = "indexId", value = "索引ID", required = true)})
    @GetMapping("indexTree")
    public DimRep indexTree(String indexId) {
        return iCatalogService.findIndexDimTree(false,indexId);
    }

    @ApiOperation(value = "获取个人标签目录列表-敏感", notes = "标签目录管理")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "query", name = "indexId", value = "索引ID", required = true)})
    @GetMapping("sensitiveShowList")
    public DimRep sensitiveShowList(String indexId) {
        return iCatalogService.findShowCatalogList(true,indexId);
    }

    @ApiOperation(value = "获取标签目录列表", notes = "标签目录管理")
    @GetMapping("sensitiveTree")
    public DimRep sensitiveTree() {
        return iCatalogService.findDimTree(true);
    }

    @ApiOperation(value = "index-获取标签目录列表", notes = "标签目录管理")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "query", name = "indexId", value = "索引ID", required = true)})
    @GetMapping("indexSensitiveTree")
    public DimRep indexSensitiveTree(String indexId) {
        return iCatalogService.findIndexDimTree(true,indexId);
    }

    @ApiOperation(value = "移除某个目录", notes = "标签目录管理")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "query", name = "id", value = "标签目录ID", required = true)})
    @DeleteMapping("del")
    public DimRep del(String id) {
        return iCatalogService.del(id);
    }

    @ApiOperation(value = "新增某个目录", notes = "标签目录管理")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "query", name = "parentId", value = "标签目录上级目录ID，一级目录传入-", required = true), @ApiImplicitParam(paramType = "query", name = "name", value = "标签目录名称", required = true), @ApiImplicitParam(paramType = "query", name = "number", value = "排序编号", required = true)})
    @PostMapping("add")
    public DimRep put(String parentId, String name, Integer number) {
        return iCatalogService.put(parentId, name, number);
    }

    @ApiOperation(value = "修改某个目录", notes = "标签目录管理")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "query", name = "id", value = "标签目录ID", required = true), @ApiImplicitParam(paramType = "query", name = "parentId", value = "标签目录上级目录ID"), @ApiImplicitParam(paramType = "query", name = "name", value = "标签目录名称"), @ApiImplicitParam(paramType = "query", name = "number", value = "排序编号")})
    @PostMapping("update")
    public DimRep update(String id, String parentId, String name, Integer number) {
        return iCatalogService.update(id, parentId, name, number);
    }

    @ApiOperation(value = "获取当前目录下的标签-不包含共享标签", notes = "标签目录管理")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "query", name = "id", value = "标签目录ID", required = true)})
    @GetMapping("dimList")
    public DimRep dimList(String id) {
        return iCatalogService.dimList(id);
    }

    @ApiOperation(value = "index-获取当前目录下的标签-不包含共享标签", notes = "标签目录管理")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "id", value = "标签目录ID", required = true),
            @ApiImplicitParam(paramType = "query", name = "indexId", value = "索引ID", required = true)
    })
    @GetMapping("indexDimList")
    public DimRep indexDimList(String id,String indexId) {
        return iCatalogService.indexDimList(id,indexId);
    }


    @ApiOperation(value = "index-获取有效组合标签列表", notes = "标签目录管理")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "indexId", value = "索引ID", required = true)
    })
    @GetMapping("indexCombination")
    public DimRep indexCombination(String indexId) {
        return iCatalogService.indexCombiantion(indexId);
    }

    @ApiOperation(value = "获取当前目录下的所有标签", notes = "标签目录管理")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "query", name = "id", value = "标签目录ID", required = true)})
    @GetMapping("allDimList")
    public DimRep dimAllList(String id) {
        return iCatalogService.dimAllList(id);
    }

    @ApiOperation(value = "获取当前目录下的收藏的标签", notes = "标签目录管理")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "query", name = "id", value = "标签目录ID", required = true)})
    @GetMapping("dimListInMine")
    public DimRep dimListInMine(String id) {
        return iCatalogService.dimListInMine(id);
    }

    @ApiOperation(value = "index-获取当前目录下的收藏的标签", notes = "标签目录管理")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "id", value = "标签目录ID", required = true),
            @ApiImplicitParam(paramType = "query", name = "indexId", value = "索引ID", required = true)
    })
    @GetMapping("indexDimListInMine")
    public DimRep indexDimListInMine(String id,String indexId) {
        return iCatalogService.indexDimListInMine(id,indexId);
    }

    @ApiOperation(value = "我收藏的标签的标签目录", notes = "标签目录管理")
    @GetMapping("listInMine")
    public DimRep listInMine() {
        return iCatalogService.listInMine();
    }

    @ApiOperation(value = "根据父id查找其下的标签和目录", notes = "标签目录管理")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "query", name = "parentId", value = "标签目录父ID", required = true)})
    @GetMapping("findDimAndCatalog")
    public DimRep findDimAndCatalog(String parentId) {
        return iCatalogService.findDimAndCatalog(parentId);
    }

    @ApiOperation(value = "根据目录名称查询目录ID", notes = "标签目录管理")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "catalogName", value = "目录名称", required = true)})
    @GetMapping("/getCatalogIdByName")
    public DimRep getCatalogIdByName(String catalogName) {
        String catalogId= iCatalogService.findCatalogByName(catalogName);
        return new DimRep(catalogId,0,"查询成功");
    }


}
